﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Ooaavee.Scripting.Remoting
{
    /// <summary>
    /// Script parameters.
    /// </summary>
    [Serializable]
    public sealed class RemoteScriptParameters : IEnumerable<object>
    {
        private readonly Collection<object> _parameters = new Collection<object>();

        /// <summary>
        /// Creates a new instance of <see cref="RemoteScriptParameters"/> class.
        /// </summary>
        internal RemoteScriptParameters()
        {
        }

        /// <summary>
        /// Creates a new instance of <see cref="RemoteScriptParameters"/> class.
        /// </summary>
        /// <param name="parameters">script parameters</param>
        internal RemoteScriptParameters(params object[] parameters)
        {
            foreach (object parameter in parameters)
            {
                _parameters.Add(parameter);
            }
        }

        /// <summary>
        /// Gets the number of parameters.
        /// </summary>
        public int Count
        {
            get { return _parameters.Count; }
        }

        /// <summary>
        /// Gets the parameter at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the parameter to get.</param>
        /// <returns>The parameter at the specified index.</returns>
        /// <exception cref="ArgumentOutOfRangeException">index is less than zero or index is equal to or greater than Count.</exception>
        public object this[int index]
        {
            get { return _parameters[index]; }
        }

        #region IEnumerable<object> Members

        public IEnumerator<object> GetEnumerator()
        {
            return _parameters.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion
    }
}